<template>
  <div class="brand-wrapper">
    <!--    搜索区域-->
    <div class="search-box">
      <el-form :inline="true" class="demo-form-inline" size="mini">
        <el-form-item label="品牌名称">
          <el-input v-model="searchForm.brandName" placeholder="请输入品牌名称"></el-input>
        </el-form-item>
        <el-form-item label="品牌描述">
          <el-input v-model="searchForm.brandDesc" placeholder="请输入品牌描述"></el-input>
        </el-form-item>
        <el-date-picker
            v-model="chooseDate"
            style="width: 280px"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="chooseDateChange"
            size="mini"
            align="right">
        </el-date-picker>
        <el-form-item style="margin-left: 10px">
          <el-button type="primary" @click="searchPage">搜索</el-button>
          <el-button type="warning" @click="resetSearchForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--    操作区域  -->
    <div class="exec-box">
      <el-button type="primary" size="mini" @click="addBtnClick" v-hasperm="'good:brand:add'">新建</el-button>
      <el-button type="success" size="mini" :disabled="selectIds.length!=1"
                 v-hasperm="'good:brand:edit'"
                 @click="createDialog=true,findById(selectIds[0])">编辑
      </el-button>
      <el-button type="danger" size="mini" :disabled="selectIds.length<=0" @click="showBatchDeleteDialog"  v-hasperm="'good:brand:batch'">删除</el-button>
    </div>
    <!--    数据表格-->
    <el-scrollbar>
      <el-table
          @selection-change="selectChange"
          :data="tableData"
          style="width: 100%">
        <el-table-column
            type="selection"
            align="center"
            width="55"/>
        <el-table-column
            align="center"
            prop="id"
            label="品牌id"
            width="80"
        >
        </el-table-column>
        <el-table-column
            align="center"
            prop="brandName"
            label="品牌名称"
        >
        </el-table-column>

        <el-table-column
            align="center"
            label="品牌站点"
        >
          <template v-slot="obj">
            <el-link type="primary" target="_blank" :href="obj.row.brandSite">{{ obj.row.brandSite }}</el-link>
          </template>

        </el-table-column>
        <el-table-column
            align="center"
            prop="brandDesc"
            label="品牌描述"
        >
        </el-table-column>
        <el-table-column
            align="center"
            label="品牌LOGO"
        >
          <template v-slot="obj">
            <img :src="obj.row.brandLogo" width="100px" height="35px"/>
          </template>
        </el-table-column>

        <el-table-column
            align="center"
            label="操作"
        >
          <template v-slot="obj">
            <el-button type="success" size="mini" @click="findById(obj.row.id)"  v-hasperm="'good:brand:edit'">编辑</el-button>
            <el-popconfirm
                style="margin-left: 8px"
                confirm-button-text='好的'
                cancel-button-text='不用了'
                icon="el-icon-info"
                @confirm="deleteById(obj.row.id)"
                icon-color="red"
                title="这是一段内容确定删除吗？"
            >
              <el-button slot="reference" size="mini" type="danger"  v-hasperm="'good:brand:delete'">删除</el-button>
            </el-popconfirm>

          </template>

        </el-table-column>

      </el-table>

      <!--    分页区域 -->
      <div class="page-box">
        <el-pagination
            background
            layout="prev, pager, next"
            @current-change="pageChange"
            :page-size="searchForm.pageSize"
            :current-page="searchForm.currentPage"
            :total="total">
        </el-pagination>
      </div>
    </el-scrollbar>

    <!--    新建弹框-->
    <el-dialog
        title="实体操作"
        :visible.sync="createDialog"
        width="40%">
      <el-form ref="form" label-width="80px" :model="formData" :rules="rules" label-position="middle" size="mini">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="品牌名称" prop="brandName">
              <el-input v-model="formData.brandName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="品牌站点" prop="brandSite">
              <el-input v-model="formData.brandSite"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="品牌图标">
          <!--          <el-input v-model="formData.brandLogo"></el-input>-->
          <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :http-request="chooseImg"
              :show-file-list="false">
            <img v-if="imgUrl" :src="imgUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="品牌描述">
          <el-input v-model="formData.brandDesc"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="createDialog = false" size="mini">取 消</el-button>
    <el-button type="success" @click="addOrEdit" size="mini">确 定</el-button>
  </span>
    </el-dialog>
  </div>

</template>

<script src="./index.js"></script>

<style src="./index.scss" lang="scss">

</style>
